package com.topsec.erp.controller;

import com.topsec.erp.entity.AdminUser;
import com.topsec.erp.service.AdminUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * author: zsl
 * date: 2019/11/22 11:13
 * Description:
 */
@Controller
public class AdminUserController {
    // 日志记录器
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private AdminUserService adminUserService;


    @RequestMapping(value="/adminuser/updatePage",method= RequestMethod.GET)
    public String update(Model model, Long id){
        AdminUser byId = adminUserService.findById(id);
        model.addAttribute("user",byId);

        return "/adminuser/add";
    }


    @RequestMapping(value="/adminuser/add",method=RequestMethod.POST)
    public String add(@RequestParam("id") Long id,
                      @RequestParam("password") String password ){
        AdminUser user = adminUserService.findById(id);
        user.setPassword(password);
        if(id != null){
            user.setId(id);
        }
        adminUserService.save(user);

        return "/welcome";
    }


}
